package cn.hzking.gjmall.adpters.coupon;

import android.content.Intent;
import android.graphics.Color;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import org.greenrobot.eventbus.EventBus;

import java.sql.Time;
import java.text.ParseException;
import java.util.List;

import cn.hzking.gjmall.R;
import cn.hzking.gjmall.activitys.MainActivity;
import cn.hzking.gjmall.activitys.order.PaySuccessActivity;
import cn.hzking.gjmall.adpters.order.OrderDetailItemAdapter;
import cn.hzking.gjmall.bean.MyCouponBean;
import cn.hzking.gjmall.bean.order.OrderDetailBean;
import cn.hzking.gjmall.utils.FormatUtil;
import cn.hzking.gjmall.utils.ListUtils;
import cn.hzking.gjmall.utils.TimeManagement;

/**
 * Created by Administrator on 2018/3/2.
 */

public class MyCouponAdapter extends BaseQuickAdapter<MyCouponBean.DataBean.CouponDetailQueryBean.ModuleBean,BaseViewHolder> {
    public MyCouponAdapter(int layoutResId, @Nullable List<MyCouponBean.DataBean.CouponDetailQueryBean.ModuleBean> data) {
        super(layoutResId, data);
    }
    private String couponType;

    public String getCouponType() {
        return couponType;
    }

    public void setCouponType(String couponType) {
        this.couponType = couponType;
    }

    @Override
    protected void convert(BaseViewHolder helper, final MyCouponBean.DataBean.CouponDetailQueryBean.ModuleBean item) {
        TextView priceTv=helper.getView(R.id.coupon_price);
        TextView limitTv=helper.getView(R.id.coupon_limit);
        TextView rangeTv=helper.getView(R.id.coupon_fanwei);
        TextView nameTv=helper.getView(R.id.coupon_name);
        TextView timeTv=helper.getView(R.id.coupon_time);
        TextView userTv=helper.getView(R.id.coupon_user);
        LinearLayout ll=helper.getView(R.id.ll);
        if (getCouponType().equals("unusedCoupon")){
            ll.setBackgroundResource(R.mipmap.quan_bg);
            priceTv.setTextColor(Color.parseColor("#C30D23"));
            limitTv.setTextColor(Color.parseColor("#231815"));
            rangeTv.setTextColor(Color.parseColor("#231815"));
            nameTv.setTextColor(Color.parseColor("#231815"));
            timeTv.setTextColor(Color.parseColor("#231815"));
            userTv.setTextColor(Color.parseColor("#C30D23"));
            userTv.setBackgroundResource(R.drawable.shap_coupon);
        }else if(getCouponType().equals("usedCoupon")){
            ll.setBackgroundResource(R.mipmap.quan_bghui);
            priceTv.setTextColor(Color.parseColor("#959595"));
            limitTv.setTextColor(Color.parseColor("#959595"));
            rangeTv.setTextColor(Color.parseColor("#959595"));
            nameTv.setTextColor(Color.parseColor("#959595"));
            timeTv.setTextColor(Color.parseColor("#959595"));
            userTv.setTextColor(Color.parseColor("#959595"));
            userTv.setBackgroundResource(R.drawable.shape_coupongray);
        }else if(getCouponType().equals("expireCoupon")){
            ll.setBackgroundResource(R.mipmap.quan_bghui);
            priceTv.setTextColor(Color.parseColor("#959595"));
            limitTv.setTextColor(Color.parseColor("#959595"));
            rangeTv.setTextColor(Color.parseColor("#959595"));
            nameTv.setTextColor(Color.parseColor("#959595"));
            timeTv.setTextColor(Color.parseColor("#959595"));
            userTv.setTextColor(Color.parseColor("#959595"));
            userTv.setBackgroundResource(R.drawable.shape_coupongray);
        }
        userTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (getCouponType().equals("unusedCoupon")) {
                    if((item.getCouponItemType().equals("ALL")||item.getCouponItemType().equals("all"))){
                        EventBus.getDefault().post("goHome");
                        Intent intent = new Intent(mContext, MainActivity.class);
                        mContext.startActivity(intent);
                    }else if(item.getCouponItemType().equals("GROUP")||item.getCouponItemType().equals("group")){

                    }
                }
            }
        });
        priceTv.setText(""+FormatUtil.format(item.getFaceValue()));
        if(item.getEnoughMoney()>0){
            limitTv.setText("满¥"+FormatUtil.format(item.getEnoughMoney())+"使用");
        }else {
            limitTv.setText("无金额门槛");
        }
        nameTv.setText(item.getName());
        if(item.getCouponItemType().equals("ALL")||item.getCouponItemType().equals("all")){
            rangeTv.setText("全场通用");
        }else if(item.getCouponItemType().equals("GROUP")||item.getCouponItemType().equals("group")) {
            rangeTv.setText("指定专区使用");
        }
        try {
            timeTv.setText(TimeManagement.getDate(item.getBeginTime())+"/"+ TimeManagement.getDate(item.getEndTime()));
        } catch (ParseException e) {
            e.printStackTrace();
        }

    }
}
